#include <maya/MPlug.h>
#include <maya/MObjectArray.h>

class VUtil {

public:
	
	static bool IsMesh(MObject& object);
	static bool IsTransform(MObject& object);
	static bool IsLight(MObject& object);
	static bool IsTextureSupported(MObject& object);
	static bool IsMaterialSupported(MObject& object);
	static bool IsInstanceSampler(MObject& object);

	static bool GetMeshByName(MString& name, MObject& targetObject);
	static bool GetMaterialByName(MString& name, MObject& materialObject);
	static bool GetPartMaterial(MObject& object, uint index, MObject& material);

	static bool GetProceduralByName(MString& name, MObject& proceduralTextureObject);
	static bool GetSamplerByName(MString& name, MObject& surfaceTextureObject);	
	static bool GetStandardSamplerTokens(MObject& object, MObject& targetMesh, UINT* pPartIndex, MString& targetChannel);	
	static bool GetInstanceSamplerTokens(MObject& object, MObject& targetMesh, MObject& targetChild, MString& targetChannel);	
	
	static bool GetMeshTransform(MObject& object, MObject& transform);
	static bool GetMeshTriangleCount(MObject& object, u_int& triangleCount);
	static bool GetMeshMaterials(MObject& object, MObjectArray& materials);
	static bool GetMeshMaterial(MObject& object, u_int index, MObject& material);
	/*static bool GetMeshVertexFormat(MObject& object, u_int& vertexFormat);*/
	static int GetMeshPartCount(MObject& object);

	static bool GetMeshInstanceProcedrual(MObject& targetObject, MString& channel, MObject& proceduralTexture);
	
	static bool GetMaterialDecal(MObject& material, MObject& textureObject);
	static bool GetMaterialNormal(MObject& material, MObject& textureObject);
	static bool GetMaterialAux(MObject& material, MObject& textureObject);

	static bool GetSceneLights(MObjectArray& lights);
	static bool GetSceneMeshes(MObjectArray& meshes);
	static bool GetSceneSamplers(MObjectArray& samplers);
	static bool GetSceneObjects(MObjectArray& objects, MFn::Type type);

	static bool GetTextureFilename(MObject& texture, MString& filename);
	static bool GetTransformMesh(MObject& object, MObject& mesh);
	static bool GetTransformChild(MObject& object, MObject& child, MFn::Type type);
	static bool GetTransformLight(MObject& object, MObject& light);

	static bool GetObjectTransform(MObject& object, MObject& transform);
	static bool GetObjectName(MObject& object, MString& objectName);
	static bool GetInstanceMeshParents(MObject& meshInstance, MObjectArray& meshInstanceParents);
	static bool GetObjectAttribute(MObject& root, MString& attributeName, MPlug& attributePlug);
	static bool TraverseDAGForType(MObject& root, MFn::Type type, MObject& node);
	
	static bool GetSceneLight(uint index, MObject& object);

	static bool RemoveAttribute(MObject& target, MString& label);

	static bool SetStringArrayAttribute(MObject& target, MString& label, uint index, MString& value);
	static bool GetStringArrayAttribute(MObject& target, MString& label, MStringArray& value);

	static bool SetAttribute(MObject& target, MString& label, MString& value, bool autoAdd = true);
	static bool SetAttribute(MObject& target, MString& label, int value, bool autoAdd = true);
	static bool SetAttribute(MObject& target, MString& label, float value, bool autoAdd = true);
	
	static bool SetCompoundAttribute(MObject& target, MString& label, float value, bool autoAdd = true);

	static bool GetAttribute(MObject& target, MString& label, MString& out);
	static bool GetAttribute(MObject& target, MString& label, int& out);
	static bool GetAttribute(MObject& target, MString& label, float& out);
};